package com.shop.shoporder.wapController;

import com.shop.shoporder.common.MessageConstants;
import com.shop.shoporder.common.Response;
import com.shop.shoporder.service.Owner.OwnerOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

@CrossOrigin
@Controller
@RequestMapping("/wap")
public class WapOrderOwnerController {

    @Autowired
    OwnerOrderService ownerOrderService;

    @ResponseBody
    @RequestMapping("/getOwnerOrderAmount")
    public Response getOwnerOrderAmount(HttpServletRequest request) {
        String userNoIdList = request.getParameter("userNoIdList");
        String zoneIdList = request.getParameter("zoneIdList");
        if (userNoIdList!="") {
//            try {
                double ownerOrderAmount =0 ;
                if(zoneIdList!=null)
                {
                    List<String> listString = Arrays.asList(userNoIdList.split(","));
                    List<String> listString1 = Arrays.asList(zoneIdList.split(","));
                    ownerOrderAmount = ownerOrderService.getOwnerOrderZoneAmount(listString,listString1);
                    System.out.println(ownerOrderAmount);
                }else {
                    List<String> listString = Arrays.asList(userNoIdList.split(","));
                    ownerOrderAmount = ownerOrderService.getOwnerOrderAmount(listString);
                }
                return new Response(MessageConstants.MSG_SUCCESS, ownerOrderAmount, 1, "", request);
//            }catch (Exception ex)
//            {
//                return new Response(MessageConstants.MSG_SYS_ERROR, null, 0, ex.getMessage(), request);
//            }
        }
        return new Response(MessageConstants.MSG_NUMBER_FORMAT_ERROR, null, 0, "没有数据", request);
    }

    @ResponseBody
    @RequestMapping("/getOwnerOrderCount")
    public Response getOwnerOrderCount(HttpServletRequest request) {
        String userNoIdList = request.getParameter("userNoIdList");
        String zoneIdList = request.getParameter("zoneIdList");
        if (userNoIdList!="") {
//            try {
            int ownerOrderCount =0 ;
            if(zoneIdList!=null)
            {
                List<String> listString = Arrays.asList(userNoIdList.split(","));
                List<String> listString1 = Arrays.asList(zoneIdList.split(","));
                ownerOrderCount = ownerOrderService.getOwnerOrderZoneCount(listString,listString1);
                System.out.println(ownerOrderCount);
            }else {
                List<String> listString = Arrays.asList(userNoIdList.split(","));
                ownerOrderCount = ownerOrderService.getOwnerOrderCount(listString);
            }
            return new Response(MessageConstants.MSG_SUCCESS, ownerOrderCount, 1, "", request);
//            }catch (Exception ex)
//            {
//                return new Response(MessageConstants.MSG_SYS_ERROR, null, 0, ex.getMessage(), request);
//            }
        }
        return new Response(MessageConstants.MSG_NUMBER_FORMAT_ERROR, null, 0, "没有数据", request);
    }

}
